<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html lang="zh-cn">
<html>
    <head>
        <%
            String rootPath = request.getContextPath();
            request.setAttribute("rootPath", rootPath);
        %>
        <title>征程</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">

        <!-- Bootstrap -->
        <link href="${rootPath}/static/bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet" media="screen">
        <link href="${rootPath}/static/bootstrap/3.3.7/css/bootstrap-theme.css" rel="stylesheet" media="screen">
        <link href="${rootPath}/static/bootstrap/3.3.7/css/bootstrap-admin-theme.css" rel="stylesheet" media="screen">
        <link rel="stylesheet" href="${rootPath}/static/my/css/style.css">

    </head>
    <body class="bootstrap-admin-with-small-navbar">
    <nav class="navbar navbar-default navbar-inverse navbar-fixed-top " role="navigation">
        <div class="container">
            <div class="row">
                <!-- Brand and toggle get grouped for better mobile display -->
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand" href="#">后台管理</a>
                </div>
                <!-- Collect the nav links, forms, and other content for toggling -->
                <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                    <ul class="nav navbar-nav navbar-right">
                        <li><a href="${rootPath}/index/show">前台</a></li>
                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown">管理员<b class="caret"></b></a>
                            <ul class="dropdown-menu">
                                <li><a href="#">账户中心</a></li>
                                <li class="divider"></li>
                                <li><a href="#">退出登录</a></li>
                            </ul>
                        </li>
                    </ul>
                </div><!-- /.navbar-collapse -->
            </div>
        </div>
    </nav>

    <div class="container">
        <!-- left, vertical navbar & content -->
        <div class="row">
            <!-- left, vertical navbar -->
            <div class="col-md-2 bootstrap-admin-col-left">
                <ul class="nav navbar-collapse collapse bootstrap-admin-navbar-side">
                    <li>
                        <a href="${rootPath}/manage/index/showback"> 友链</a>
                    </li>
                    <li>
                        <a href="${rootPath}/manage/video/showback"> 视频</a>
                    </li>
                    <li class="active">
                        <a href="${rootPath}/manage/msg/showback"> 留言</a>
                    </li>
                    <li>
                        <a href="${rootPath}/manage/user/showback/"> 用户</a>
                    </li>
                </ul>
            </div>

            <!-- content -->
            <div class="col-md-10">
                <div class="row bootstrap-admin-no-edges-padding">
                    <div class="col-md-12">
                        <div class="panel panel-default">
                            <div class="panel-heading">
                                <div class="text-muted bootstrap-admin-box-title">留言</div>
                            </div>
                            <div class="bootstrap-admin-panel-content">
                                <c:forEach items="${msgList}" var="item" varStatus="status">
                                    <hr>
                                    <div>
                                        <input type="checkbox" name="checkbox" value="${item.id}">
                                        <div style="float: right">
                                            posted by:${item.name}&nbsp;&nbsp;&nbsp;时间:<fmt:formatDate value='${item.time}' pattern='yyyy-MM-dd  HH:mm:ss'/>
                                        </div>
                                        <br>
                                        <div style="margin-top: 20px">
                                            ${item.content}
                                        </div>
                                    </div>
                                </c:forEach>
                            </div>
                            <hr>
                            <div class="put-btn1">
                                总共${msgPageSum}页&nbsp;&nbsp;&nbsp;&nbsp;
                                <c:if test="${msgPageNum > 1}">
                                    <a href="${rootPath}/manage/msg/jump?pagenum=${msgPageNum-1}">上一页</a>
                                </c:if>
                                第${msgPageNum}页
                                <c:if test="${msgPageNum < msgPageSum}">
                                    <a href="${rootPath}/manage/msg/jump?pagenum=${msgPageNum+1}">下一页</a>
                                </c:if>&nbsp;&nbsp;&nbsp;&nbsp;
                                去第<input type="text" size="2" id="jumppage">页&nbsp;&nbsp;&nbsp;&nbsp;
                                <input class="btn btn-default" type="button" value="跳转" id="jump">
                                <input class="btn btn-default" type="button" value="删除" id="delete">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="row">
            <hr>
            <footer role="contentinfo">
                <p>&copy; 2017 <a href="#" target="_blank">征程</a></p>
            </footer>
        </div>
        </div>

    <script type="text/javascript" src="${rootPath}/static/jquery/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" src="${rootPath}/static/bootstrap/3.3.7/js/bootstrap.min.js"></script>

    <script type="text/javascript">
        // 删除选中的比赛，并且刷新页面
        $("#delete").click(function () {
            var idArray = new Array();
            $('input[name="checkbox"]:checked').each(function () {
                idArray.push($(this).val());
            }) ;
            var idStr = idArray.join(',');
            $.ajax({
                type : 'POST',
                url : "${rootPath}/manage/msg/delete",
                data: 'jsonStr=' + idStr,
                success : function () {
                    //删除完数据重新刷新页面
                    window.location.href = "${rootPath}/manage/msg/showback";
                },
                error : function () {
                    //删除完数据重新刷新页面
                    window.location.href = "${rootPath}/manage/msg/showback";
                }
            })
        });
        //跳转页面
        $("#jump").click(function () {
            val = $("#jumppage").val();
            if (val >= 1 && val <= ${msgPageSum}) {
                window.location.href="${rootPath}/manage/msg/jump?pagenum="+val;
            }
        })
    </script>
    </body>
</html>
